package com.example.springboot.mapper;


import com.example.springboot.entity.jobs;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface JobsMapper {

    @Select("SELECT * FROM jobs")
    List<jobs> findAll();

    @Select("SELECT * FROM jobs WHERE job_id = #{job_id}")
    jobs findById(int job_id);

    @Insert("INSERT INTO jobs(job_title, job_description) VALUES(#{job_title}, #{job_description})")
    @Options(useGeneratedKeys = true, keyProperty = "jobId")
    void insert(jobs job);

    @Update("UPDATE jobs SET job_title=#{job_title}, job_description=#{job_description} WHERE job_id=#{job_id}")
    void update(jobs job);

    @Delete("DELETE FROM jobs WHERE job_id=#{job_id}")
    void delete(int job_id);

    @Select("SELECT * FROM jobs")
    List<jobs> getAllJobs();

    @Select("SELECT * FROM jobs WHERE job_id = #{id}")
    jobs getJobById(@Param("id") Integer id);

    @Insert("INSERT INTO jobs (company_id, job_title, job_description, requirements, location, salary, posted_at, deadline) " +
            "VALUES (#{company_id}, #{job_title}, #{job_description}, #{requirements}, #{location}, #{salary}, #{posted_at}, #{deadline})")
    void addJob(jobs job);

    @Update("UPDATE jobs SET company_id = #{company_id}, job_title = #{job_title}, job_description = #{job_description}, " +
            "requirements = #{requirements}, location = #{location}, salary = #{salary}, posted_at = #{posted_at}, deadline = #{deadline} " +
            "WHERE job_id = #{job_id}")
    void updateJob(jobs job);

    @Delete("DELETE FROM jobs WHERE job_id = #{id}")
    void deleteJob(@Param("id") Integer id);

}
